<?php include("../includes/header-admin.php") ?>
<title>LazySwim</title>
<link rel="stylesheet" href="store.css" type="text/css" />
</head>
<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
				<!-- Header Goes Here -->
                <?php printHeader(); ?>
				<!-- Header Ends Here -->
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
				<!-- Welcome Message Starts Here -->
                    <ul>
					<?php include("../../includes/welcomeBar.php"); ?>
					</ul>
				<!-- Welcome Message Ends Here -->	
                </div>
            </div>
            <div id="main">
                <div id="sidebar">                 
                    <?php
					// include the corresponding navigation pages
                    include("../../includes/navigation.php");
					?>     
                </div>                     

            <!-- main body -->
 			<div class="featured-post"> 
			
				<div class="post-title"><h2> <a href="index.php">Manage Store</a> - View Orders</h2></div>
				<div class="post-entry">
                
                
                 <?php
                    $transactionID = $_GET['tx'];    
                    $success = $_GET['auth'];
                    if( $success ) {
                        echo "Thank you for your payment. Orders have been updated!<br>";
                    }
                ?>
				
				<?php
				include("paging.php");    
				// for paging 
				// how many rows to show per page 
				$rowsPerPage = 15; 

				$sql = "SELECT * FROM orders ORDER BY orderTime";  
				$result = mysql_query(getPagingQuery($sql, $rowsPerPage)) or die(mysql_error());
				$pagingLink = getPagingLink($sql, $rowsPerPage); 
						   
				?>
				
				<form name="processOrdersForm" action="processOrders.php" method="post">
					<input type="submit" name="submit" value="Process Orders">
				</form>
				
				<table width="65%" cellpadding="5" cellspacing="5" class="text"> 
					<tr align="center" id="listTableHeader"> 
						<th>Order Number</th> 
						<th>Customer Name</th> 
						<th>Time</th> 
						<th>Order Status</th>
					</tr> 
				<?php                        
				$i = 0;
				while($row = mysql_fetch_assoc($result)) { 
					// this is just to make the table pretty with alternating tr colours
					if($i % 2) { 
						$class = 'row1'; 
					} 
					else { 
						$class = 'row2'; 
					} 
					$i++;
					
					$customerName = mysql_query("SELECT name from accounts WHERE userID = '$row[customerID]'") or "Error fetching customer name";
					$customerName = mysql_fetch_row($customerName);
					
					?>
					<tr class="<?php echo $class; ?>"> 
						<td align="center"><a href="viewOrder.php?orderID=<?php echo $row[orderID]; ?>"><?php echo $row[orderID]; ?></a></td> 
						<td align="center"><?php echo $customerName[0]; ?></td> 
						<td align="center"><?php echo $row[orderTime]; ?></td>
						<td align="center"><?php echo $row[status]; ?></td>
					</tr> 
					  <?php                    
					} // end of while
					?>
					<tr> 
						<td colspan="5" align="center"> 
							<?php echo $pagingLink; ?>
						</td> 
					 </tr> 
				</table>
				<!-- end of main -->
				</div>
			</div>
				
            <div class="clear"></div>

            </div>
			<!-- Footer Goes Here -->
            <?php include("../../includes/footer.php"); ?>
			<!-- Footer Ends Here -->
        </div>
    </div>
</div>
</body>
</html>